<template>
	<u-upload :action="upLoadAction" class="u-row-center" :form-data="formData" :upload-text="upText" :width="width"
		:height="height" @on-error="error" @on-success="uploadSuccess" :max-count="maxCount"></u-upload>
</template>

<script>
	export default {
		name: "upLoader",
		data() {
			return {
				formData: {}, // formData数据
				upLoadAction: '', //提交地址
				resultSrc: '', //返回结果
				remotePath: '', //服务上存放的目录
			}
		},
		props: {
			apiUrl: {
				type: String,
				default: 'api/Common/uploadPic'
			},
			// remotePath:{
			//   type:String,
			//   default:'applyinfo'
			// },
			upText: {
				type: String,
				default: '上传图片'
			},
			width: {
				type: Number,
				default: 200
			},
			height: {
				type: Number,
				default: 200
			},
			maxCount: {
				type: Number,
				default: 1
			}
		},
		mounted() {
			this.upText = '上传图片'
			const baseURL = uni.getStorageSync('baseUrl')
			this.upLoadAction = `${baseURL}${this.apiUrl}`
			this.formData = this.$http.returnCommonParams(this.apiUrl, this.remotePath)
		},

		methods: {
			uploadSuccess(e) {
				this.resultSrc = e.data[0].dz
			},
			error(e) {
				this.$toast(e)
			}
		}
	}
</script>
